package com.lhn.spring5.test;

import com.lhn.spring5.config.SpringConfig;
import com.lhn.spring5.service.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

/**
 * 〈一句话功能简述>
 * 〈测试类〉
 *
 * @Author 17505
 * @Create 2021/12/26
 * @Since 1.0.0
 */
@Repository
public class SpringTest1 {

    @Autowired
    private UserService userService;

    @Test
    public void testServices() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        UserService userService = context.getBean("userService", UserService.class);
        userService.add();
    }

    @Test
    public void autowire() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        userService.add();
    }

    @Test
    public void annotationTest() {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = context.getBean("userService", UserService.class);
        userService.add();
    }

    @Test
    public void circularDependencies() {
        //new ServiceA(new ServiceB(new ServiceA()));
        new ServiceAA().setServiceBB(new ServiceBB());
    }

}